package com.company.finance.ddd.domain.core.bill.repository;

import com.company.finance.ddd.common.IRepository;
import com.company.finance.ddd.domain.core.bill.aggregate.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author wanglei
 * @version $$Id: BillRepository, v 0.1 2021/2/4 13:36 wanglei Exp $$
 */
@Repository
public class BillRepository implements IRepository<BillAggregate> {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void save(BillAggregate billAggregate) {

    }

    @Override
    public List<BillAggregate> query(Map<String, Object> queryCondition) {
        return Collections.emptyList();
    }

    @Override
    public BillAggregate get(Long id) {
        Object[] params = {id};
        return BillAggregate.builder().bill(jdbcTemplate
                .queryForObject("select b.*, c.relate_deal, c.company_name " +
                                "from bill b, company c " +
                                "where b.id = ? and b.company_id = c.id"
                , params, new BeanPropertyRowMapper<>(Bill.class))).build();
    }

    @Override
    public void delete(Long billId) {
        throw new UnsupportedOperationException();
    }
}
